<template>
	<div class="returngoods">
		<back :title="title"></back> 
	    <body class="body">
	    	<p class="tips" v-show="isShow">暂时还没有产品哦~</p>
	       <div class="seriallist">
	   	      <div class="box" v-for="(item,index) in serialList" @click="scan(item)">
	   	      	<p>{{item}}</p>
	   	      </div>
	      </div>
	    </body>
	</div>
</template>

<script>
import back from '@/components/m-shop/m-store/back'
import wx from 'weixin-js-sdk'

  
export default {
	name:'returngoods',
	components: {
		back
	  },
	data () {
		return {
			title:'产品退货',
			isShow:false,
			placehold:'请选择订单号',
			serialList:[],
			isShow:false
		}
	},
	created () {
		this.getOrderSerial()
	},
	mounted () {
				
	},
	methods:{
		//调微信扫描
		scan (purchaseOrderSerial) {	
			     //result = ""
				//这里【url参数一定是去参的本网址】
				//获取微信认证参数的地址
				//console.log(3)
				let _this = this;
				let axios = this.$http.put;
				let reqUrl = this.$store.state.reqUrl;
				let shopId = this.$store.state.shop_id
				
				let url = location.href.split('#')[0];
				
				this.$http.get("http://www.ewj100.com/ewj/shop/wx/jsapi/createJsapiSignature?url="+url,{}).then(res => {
					wx.config({
						debug: false,
						// 必填，公众号的唯一标识               
						appId:res.data.appId,
						// 必填，生成签名的时间戳              
						timestamp: res.data.timestamp,
						// 必填，生成签名的随机串             
						nonceStr: res.data.nonceStr,
						// 必填，签名                
						signature: res.data.signature,
						// 必填，需要使用的JS接口列表，所有JS接口列表               
						jsApiList: ['checkJsApi', 'scanQRCode']
					});
			   })
				wx.error(function(res) {
					alert("出错了：" + res.errMsg);
					//这个地方的好处就是wx.config配置错误，会弹出窗口哪里错误，然后根据微信文档查询即可。
				});
				wx.ready(function() {
					wx.checkJsApi({
						jsApiList: ['scanQRCode'],
						success: function(res) {}
					});
					wx.scanQRCode({
						needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，                   
						scanType: ["qrCode"], // 可以指定扫二维码还是一维码，默认二者都有
						success: function(res) {
							   if(!!res.resultStr){
							   	 axios(reqUrl + '/shops/depurchase/depurchase/'+ purchaseOrderSerial, {
									productSerial:res.resultStr
								   }).then(res => {	
								   	  _this.$toast("退货完成")	
								    }).catch(res =>{
								 	   _this.$toast(res.response.data)	
								    })		
							   }
						 }
					});
				});
			},
		//获取订单号
		getOrderSerial () {
			this.$http.get(this.$store.state.reqUrl + '/shops/depurchase/depurchaseSerialList', {
				params:{
					shopId:this.$store.state.shop_id
				}
			}).then(res => {
				if(res.data.length === 0){
					this.isShow = true
					this.serialList = []
				}else{
					this.serialList = res.data;
				}
			})
		}
	}
}
</script>

<style lang="less" scoped>
    .returngoods {
    	width:100%;
    	margin-top: 100px;
    	.body{
    		width:100%;
    		.tips{
		   	    font-size: 34px;
			 	color: darkgray;
			 	text-align: center;
			 	margin-top: 50%;
		     }
    		.seriallist{
    			width:100%;
    			.box{
    				padding:30px 20px;
    				p{
    					font-size: 30px;
    				}
    			}
    		}
    	}
    }
</style>